/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name: 1.c
> Author:cjy
> Mail: 
> Created Time: 2024年08月07日 星期三 11时22分16秒
***************************************************/
//创建两个不同线程，分别执行不同的代码。
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
void *fun1(void *arg){
	for(int i = 0;i < 5;i++){
		printf("%dnihao:%ld\n",i,pthread_self());
		sleep(1);
	}
	
}

void *fun2(void *arg){
	for(int i = 0;i < 5;i++){
		printf("%dcjy:%ld\n",i,pthread_self());
		sleep(1);
	}
	
}
int main(int argc,const char* argv[])
{
	int ret = 0;
	pthread_t id1 = 0;
	pthread_t id2 = 0;
	pthread_t id3 = pthread_self();
	ret = pthread_create(&id1,NULL,fun1,NULL);
	if(ret != 0){
		perror("pthread_create");
		exit(-1);
	}
	ret = pthread_create(&id2,NULL,fun2,NULL);
	if(ret != 0){
		perror("pthread_create");
		exit(-1);
	}
	for(int i = 0;i < 5;i++){
		printf("%dmain_id is %ld\n",i,id3);
		sleep(1);
	}
	
	pthread_join(id1,NULL);
	pthread_join(id2,NULL);
    return 0;
}
